package portal.mybatis.dao.service;

import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import portal.beans.HostMachine;
import portal.mybatis.dao.mapper.HostMachineMapper;

import java.util.List;
import java.util.Map;

@Service
public class HostMachineService {
    @Autowired
    HostMachineMapper hostMachineMapper;

    public int updateHostById(HostMachine hostMachine){
        return hostMachineMapper.updateHostById(hostMachine);
    }
    public int updateHostById(int hostId, String hostName, String hostIp, String hostType, int hostGroupId, String hostGroupName, String hostState, String hostSSH){
        HostMachine hostMachine = new HostMachine(hostId, hostName, hostIp, hostType, hostGroupId, hostGroupName, hostState, hostSSH);
        return hostMachineMapper.updateHostById(hostMachine);
    }
    public List<HostMachine> selectByName(String hostName){
        return hostMachineMapper.selectByName(hostName);
    }
    public List<HostMachine> selectById(int hostId){
        return hostMachineMapper.selectById(hostId);
    }
    public Integer insertHost(HostMachine hostMachine){
        return hostMachineMapper.insertHost(hostMachine);
    }
    public Integer insertHost(String hostName, String hostIp, String hostType, int hostGroupId, String hostGroupName, String hostState, String hostSSH){
        HostMachine hostMachine = new HostMachine(hostName, hostIp, hostType, hostGroupId, hostGroupName, hostState, hostSSH);
        return hostMachineMapper.insertHost(hostMachine);
    }
    public int deleteById(HostMachine hostMachine){
        return hostMachineMapper.deleteById(hostMachine);
    }
    public int deleteById(int id){
        HostMachine hostMachine = new HostMachine();
        hostMachine.setHostId(id);
        return hostMachineMapper.deleteById(hostMachine);
    }
    public List<HostMachine> showAll(){
        return hostMachineMapper.showAll();
    }
    public List<HostMachine> showPaged(int currPage, int pageSize) {
        Map<String, Object> data = new HashedMap();
        data.put("currIndex", (currPage-1)*pageSize);
        data.put("pageSize", pageSize);
        return hostMachineMapper.showPaged(data);
    }
    public Long countAll() {
        return hostMachineMapper.countAll();
    }
}
